package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.QuestionDao;
import com.itheima.pojo.Question;
import com.itheima.service.QuestionService;
import com.itheima.utils.Count;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author 春夏_x
 * @date 2019-12-15 15:37
 */

@Service(interfaceClass = QuestionService.class)
@Transactional
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionDao questionDao;

    @Override
    public Question findAll(Integer onetotal) {
        Count.total += onetotal;
        if (Count.count ==0){
            Random random = new Random(8);
          for (int a=0; a<10;a++){
              int i = random.nextInt(73);
              Count.questions.add(questionDao.findAll(i));
          }
        }
        Question question = Count.questions.get(Count.count);
        Count.count++;
        if (Count.count== Count.questions.size()){
             return null;
        }
        return question;
    }
}
